//
//  productmidlistCollectionViewCell.m
//  BAOASystem
//
//  Created by michael on 2018/3/9.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "productmidlistCollectionViewCell.h"
#import "OALoginViewController.h"
#import "fajianxqViewController.h"
@implementation productmidlistCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    _imagename = [[UIImageView alloc]init];
        _imagename.frame = CGRectZero;
          [self.contentView addSubview:_imagename];
          
       _label1 = [[UILabel alloc]init];
    _label1.frame = CGRectZero;
    _label1.textColor = [UIColor colorWithHexString:@"484848"];
      [_label1 setFont:[UIFont systemFontOfSize:14]];
       [self.contentView addSubview:_label1];
    
         _label2 = [[UILabel alloc]init];
    _label2.frame = CGRectZero;
    _label2.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label2 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label2];
    
                _label3 = [[UILabel alloc]init];
    _label3.frame = CGRectZero;
    _label3.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label3 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label3];
    
                 _label4 = [[UILabel alloc]init];
    _label4.frame = CGRectZero;
    _label4.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label4 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label4];
    
          _label5 = [[UILabel alloc]init];
    _label5.frame = CGRectZero;
    _label5.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label5 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label5];
    
     _label6 = [[UILabel alloc]init];
    _label6.frame = CGRectZero;
    _label6.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label6 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label6];
    
         _label7 = [[UILabel alloc]init];
    _label7.frame = CGRectZero;
    _label7.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label7 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label7];
    
         _label8 = [[UILabel alloc]init];
    _label8.frame = CGRectZero;
    _label8.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label8 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label8];
    
         _label9 = [[UILabel alloc]init];
    _label9.frame = CGRectZero;
    _label9.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label9 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label9];
    _imagename = [[UIImageView alloc]init];
        _imagename.frame = CGRectZero;
          [self.contentView addSubview:_imagename];

 _sendbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_sendbutton addTarget:self action:@selector(sendaction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_sendbutton];
 _addbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_addbutton addTarget:self action:@selector(adddaction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_addbutton];
    _qiyebutton =[UIButton buttonWithType:UIButtonTypeCustom];
[_qiyebutton setEnabled:NO];
    [self.contentView addSubview:_qiyebutton];
     _huiyuanbutton =[UIButton buttonWithType:UIButtonTypeCustom];
[_huiyuanbutton setEnabled:NO];
    [self.contentView addSubview:_huiyuanbutton];
}

return self;

}
- (void)sendaction{
   UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];


    if (![[[NSUserDefaults standardUserDefaults]objectForKey:@"autoLogin"]isEqualToString:@"Y"]&&![[DanLi sharedDanLi].stay isEqualToString:@"yes"]) {
      OALoginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
        loginVC.navigationController.navigationBar.hidden = YES;
                 self.ViewController.view.window.rootViewController = navVC;

}else{
fajianxqViewController *vc = [[fajianxqViewController alloc]init];
vc.hidesBottomBarWhenPushed = YES;

//@property (strong, nonatomic)  NSString *toMemberCompanyId;
//@property (strong, nonatomic)  NSString *toMemberNameId;
//
//@property (strong, nonatomic)  NSString *productId;

        NSDictionary * dic = _dic;
vc.productId = dic[@"id"];
vc.toMemberNameId = dic[@"uid"];

vc.toMemberCompanyId = dic[@"cpid"];
[self.ViewController.navigationController pushViewController:vc animated:YES];

}
}
- (void)adddaction{
   UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];


    if (![[[NSUserDefaults standardUserDefaults]objectForKey:@"autoLogin"]isEqualToString:@"Y"]&&![[DanLi sharedDanLi].stay isEqualToString:@"yes"]) {
      OALoginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
        loginVC.navigationController.navigationBar.hidden = YES;
                 self.ViewController.view.window.rootViewController = navVC;

}else{
{
NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
NSString *uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"];
NSString *cpid = [[NSUserDefaults standardUserDefaults] objectForKey:@"cpid"];

NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><uid>%@</uid><cpid>%@</cpid><pid>%@</pid></body></message>",userName,password,website,language,BAtype,uid,cpid,_dic[@"id"]];
 bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bCart];
 [HttpTools requestWithURL:path arrays:array method:@"addCart" success:^(id JSON) {
   NSLog(@"%@",JSON);

    [self.ViewController.view makeToast:JSON[@"msg"]];
//[_tableView reloadData];

 } failure:^(NSError *error) {

    }];

}

}



}
- (void)layoutSubviews{
float width = (KScreenWidth -1)/2;
[super layoutSubviews];
_imagename.frame = CGRectMake(10, 10, width-20, 100);
_label1.frame = CGRectMake(10,_imagename.bottom+10, width-20, 20);
    _label2.frame = CGRectMake(10,_label1.bottom, width-20, 20);
    _label3.frame = CGRectMake(10,_label2.bottom, width-20, 20);
    _label4.frame = CGRectMake(10,_label3.bottom, width-20, 20);
     _label5.frame =CGRectMake(10,_label4.bottom, width-20, 20);
    _label6.frame = CGRectMake(10,_label5.bottom, width-20, 20);
    _label7.frame = CGRectMake(10,_label6.bottom, width-20, 20);
    _huiyuanbutton.backgroundColor = [UIColor clearColor];
[_huiyuanbutton setImage:[UIImage imageNamed:@"会员企业"] forState:UIControlStateNormal];
//[_huiyuanbutton setTitle:NSLocalizedString(@"商品详情-会员企业", nil) forState:(UIControlState)UIControlStateNormal];
[_huiyuanbutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
_huiyuanbutton.frame  = CGRectMake(10,_label7.bottom, 80, 20);
    _huiyuanbutton.titleLabel.font = [UIFont systemFontOfSize: 12.0];
    _huiyuanbutton.userInteractionEnabled=NO;
              [_huiyuanbutton setTitleColor:[UIColor colorWithHexString:@"a1a1a1"] forState:UIControlStateNormal];

_qiyebutton.backgroundColor = [UIColor clearColor];
[_qiyebutton setImage:[UIImage imageNamed:@"认证企业"] forState:UIControlStateNormal];
[_qiyebutton setTitle:NSLocalizedString(@"商品详情-认证企业", nil) forState:(UIControlState)UIControlStateNormal];
[_qiyebutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
_qiyebutton.frame  = CGRectMake(_huiyuanbutton.right,_label7.bottom,80, 20);
    _qiyebutton.titleLabel.font = [UIFont systemFontOfSize: 12.0];
    _qiyebutton.userInteractionEnabled=NO;
          [_qiyebutton setTitleColor:[UIColor colorWithHexString:@"a1a1a1"] forState:UIControlStateNormal];
                    [_imagename sd_setImageWithURL:[NSURL URLWithString:_dic[@"pdimg"]] placeholderImage:[UIImage imageNamed:@"加载"]];

                    _label1.text =[NSString stringWithFormat:@"%@",_dic[@"title"]];
           if ([[NSString stringWithFormat:@"%@",_dic[@"isPrice"] ]isEqualToString:@"0"]) {
        _label2.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"商品列表-价格", nil),NSLocalizedString(@"商品详情-价格面议", nil)];
}else{
    _label2.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"商品列表-价格", nil),_dic[@"pdPrice"]];
    }
        _label3.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"商品列表-最小起定量", nil),_dic[@"pdMinNum"]];
         _label4.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"商品列表-供货总量", nil),_dic[@"totals"]];
           _label5.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"商品列表-产品描述", nil),_dic[@"description"]];
           NSDictionary *comdic = _dic[@"pdcompany"];
    _label6.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"商品列表-企业名称", nil),comdic[@"name"]];
    _label7.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"商品列表-所在地", nil),comdic[@"areaId"]];
                    if([comdic[@"rztype"]isEqual:[NSNull null]]){

_qiyebutton.hidden = YES;
}else{
_qiyebutton.hidden = NO;

}
if([comdic[@"viptype"]isEqual:[NSNull null]]){

_huiyuanbutton.hidden = YES;
}else{
_huiyuanbutton.hidden = NO;

[_huiyuanbutton setTitle:comdic[@"viptype"] forState:(UIControlState)UIControlStateNormal];


}
    _sendbutton.frame = CGRectMake(10, _qiyebutton.bottom, 80, 20);
     [_sendbutton setImage:[UIImage imageNamed:@"我的-联系信"] forState:UIControlStateNormal];
    [_sendbutton setTitle:NSLocalizedString(@"发送信息", nil) forState:UIControlStateNormal];
    _sendbutton.titleLabel.font = [UIFont systemFontOfSize: 12.0];
      [_sendbutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft  imageTitleSpace:0];
      [_sendbutton setTitleColor:[UIColor colorWithHexString:@"0aa0f6"] forState:UIControlStateNormal];
    
     _addbutton.frame = CGRectMake(width-90, _qiyebutton.bottom, 90, 20);
     [_addbutton setImage:[UIImage imageNamed:@"购物车蓝色"] forState:UIControlStateNormal];
    [_addbutton setTitle:NSLocalizedString(@"商品详情-加入购物车", nil) forState:UIControlStateNormal];
    _addbutton.titleLabel.font = [UIFont systemFontOfSize: 12.0];
      [_addbutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft  imageTitleSpace:0];
      [_addbutton setTitleColor:[UIColor colorWithHexString:@"0aa0f6"] forState:UIControlStateNormal];
}
@end

